<?PHP
session_start();
include("common/connect.php");
include("common/common.php");

if( !isset($_SESSION["user"]) ) 
{
	$url = "Location:login.php?ref=view_recommend.php";
	header($url);
}

$nPage = SetUrlParamInt("page");
if( $nPage < 0 )
	$nPage = 0;
	
$opt = CheckUrlParamNoDie("opt");
if ($opt == "mark")
{
	$userid = CheckUrlParamNoDie("userid");
	if ($userid != "")
	{
		mysql_query("update recommend_fee set state=1,time2=now(),operater2='".$_SESSION["user"]."' where state=0 and user_id='".$userid."'");
		if (mysql_affected_rows() == 0)
		{
			echo "<script>alert('处理过程中发生失败，请告诉程序员，出错代码：1');window.history.back();</script>";
			exit;
		}
	}
	else
	{
		echo "<script>alert('参数有误！');</script>";
		exit;
	}
	
	echo "<script>window.history.back();</script>";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body,td,th {
	font-family: 宋体;
	font-size: 13px;
	color: #000;
}
body {
	background-color: #FFF;
}
-->
</style>

<script language="javascript">
function OnFind()
{
	var input_item = document.getElementById("input_id").value;
	window.location.href= "view_recommend.php?input_item=" + input_item;
}
</script>
</head>

<body>

<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
	    <td width="60" align="center">用户id</td>
    	<td height="25" width="250" align="center">支付宝账号</td>
        <td width="60" align="center">用户类型</td>
        <td width="141" align="center">手机号码</td>
        <td width="121" align="center">共推广用户数</td>
        <td width="198" align="center">上期共推广成功人数</td>
        <td width="130" align="center">推广提成(元)</td>
        <td width="200" align="center">操作</td>
    </tr>
<?php

$limit = " limit ". $nPage*20 .",20";
$input_item = CheckUrlParamNoDie("input_item");
if ($input_item == "")
	$sql = "select id,user_type, state,phone, user_id, tbid,all_under_users, sum(under_users) as tmp1,sum(fee) as tmp2 from recommend_fee where state = 0 group by user_id order by tmp2 desc".$limit;
else
	$sql = "select id,user_type, state,phone, user_id, tbid,all_under_users, under_users as tmp1,fee as tmp2 from recommend_fee where user_id=$input_item ".$limit;
	
$result = mysql_query( $sql );
while( $result && $row = mysql_fetch_assoc( $result ))
{
//	$row2 = mysql_fetch_assoc(mysql_query("select type from user where tb_id='".$row["tbid"]."' limit 1"));
//	mysql_query("update recommend_fee set user_type='".$row2["type"]."' where id=".$row["id"]);

	$_data = ($row["tbid"]."|".$row["phone"]."|".(round($row["tmp2"], 2))."|用户联盟推荐奖励|您共推荐了 ".$row["all_under_users"]." 人，其中上个月有 ".$row["tmp1"]." 人购物，根据他们的购物情况，现给您奖励 ".(round($row["tmp2"], 2))."元。另外，立即邀请您的朋友加入购物兔联盟，他们推荐的用户，也算是您的用户，您一样能得到分成奖励，详情请加联盟Q群：59518016。");
//	$_data = ($row["tbid"]."|".$row["phone"]."|".(round($row["tmp2"], 2))."|联盟推荐奖励，即日起邀请好友可拿现金红包|您共推荐了 ".$row["all_under_users"]." 人，其中上个月有 ".$row["tmp1"]." 人购物，根据他们的购物情况，现给您奖励 ".(round($row["tmp2"], 2))."元。即日起邀请您的朋友使用购物兔，您和您的朋友都有机会获得3元~100元不等的现金红包，在圣诞和元旦期间购物还可获得双倍兔币和积分，详情请关注购物兔官网。");
?>
<tr >
	<td align="center"><?PHP echo $row["user_id"]; ?></td>
    <td height="25"  align="center"><?PHP echo $row["tbid"]; ?></td>
    <td align="center"><?PHP echo $row["user_type"]; ?></td>
     <td height="25"  align="center"><?PHP echo $row["phone"]; ?>&nbsp;</td>
    <td align="center" title=""><?PHP echo $row["all_under_users"]; ?>&nbsp;</td>
	<td align="center"><?PHP echo $row["tmp1"]; ?>&nbsp;</td>
	<td align="center"><?PHP echo round($row["tmp2"], 2); ?>&nbsp;</td>
    <td align="center" title="<?PHP echo $row["state"]; ?>"><a href="view_recommend.php?opt=mark&userid=<?PHP echo $row["user_id"]; ?>">标志已返款</a>&nbsp;&nbsp;&nbsp;<a href="http://_my_data_transport_/?<?PHP echo $_data; ?>" target="_blank">去返款</a>
    &nbsp;&nbsp;<a href="notify_recommend.php?userid=<?PHP echo $row["user_id"]; ?>&tbid=<?PHP echo $row["tbid"]; ?>&phone=<?PHP echo $row["phone"]; ?>&type=<?PHP echo $row["user_type"]; ?>&all=<?PHP echo $row["all_under_users"]; ?>&thismonth=<?PHP echo $row["tmp1"]; ?>&fee=<?PHP echo intval($row["tmp2"]); ?>">发短信和邮件</a>&nbsp;</td>
	
<?PHP
}
?>
</table>

<table align="center">
	<tr>
    	<td>用户id:
    	  <input type="text" onclick="javascript:select();" value="" id="input_id" size="10"/>
    <input type="button" onclick="javascript:OnFind();" value="查找" />&nbsp;&nbsp;
	<a href="view_recommend.php">首页</a>&nbsp;&nbsp;
	<?PHP if ($nPage > 0) echo "<a href='view_recommend.php?page=".($nPage - 1)."'>上一页</a>"; ?>&nbsp;&nbsp;  
	<a href="view_recommend.php?page=<?PHP echo $nPage + 1; ?>">下一页</a>&nbsp;&nbsp;
	</td>
  </tr>
</table>

</body>
</html>
